<?php

namespace backend\modules\payment\models;

use Yii;

class AdAdsense extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%ad_adsense}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            
			 [['adsense_id','group_id','admin_id','package_name','app_name','name','type','thumbnail','thumbnail_h','desc','url','target','need_open','status','sort','addtime'],'required','message'=>'{attribute}不能为空!'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
           
				 'id' => Yii::t('app', ''),
				 'adsense_id' => Yii::t('app', '广告id对外提供'),
				 'group_id' => Yii::t('app', '广告组id'),
				 'admin_id' => Yii::t('app', '管理员id'),
				 'package_name' => Yii::t('app', '包名'),
				 'app_name' => Yii::t('app', '应用名称'),
				 'name' => Yii::t('app', '广告名称'),
				 'type' => Yii::t('app', '广告类型'),
				 'thumbnail' => Yii::t('app', '广告图'),
				 'thumbnail_h' => Yii::t('app', '广告图横屏(开屏广告)'),
				 'desc' => Yii::t('app', '广告描述'),
				 'url' => Yii::t('app', '广告链接'),
				 'target' => Yii::t('app', '打开方式'),
				 'need_open' => Yii::t('app', '安装完成马上打开'),
				 'status' => Yii::t('app', '状态'),
				 'sort' => Yii::t('app', '排序|越小越排越前面'),
				 'addtime' => Yii::t('app', '添加时间'),
        ];
    }

        public function beforeSave($insert){
        if(parent::beforeSave($insert)){
            if($this->isNewRecord){
                $this->addtime = time();
            }
            //update_time//
            return true;
        }else{
            return false;
        }
    }


    public static function get_config_type(){
            return [
                1=>['id'=>1,'name'=>'banner广告'],
				2=>['id'=>2,'name'=>'开屏广告'],
				3=>['id'=>3,'name'=>'信息流广告'],

            ];
    }

	public static function get_config_target(){
            return [
                1=>['id'=>1,'name'=>'跳转'],
				2=>['id'=>2,'name'=>'直接下载'],

            ];
    }

	public static function get_config_need_open(){
            return [
                0=>['id'=>0,'name'=>'不打开'],
				1=>['id'=>1,'name'=>'打开'],

            ];
    }

	public static function get_config_status(){
            return [
                1=>['id'=>1,'name'=>'正常'],
				-1=>['id'=>-1,'name'=>'删除'],

            ];
    }

}
